const AdminModel = require('../do/models/admin');
class AdminService {
    async addAdmin(data) {
        const { username } = data;
        const result = await AdminModel.findOne({
            where: { username }
        })
        if (result) {
            return await AdminModel.update(data, {
                where: { username }
            })
        } else {
            return await AdminModel.create(data);
        }
    }
    async login(userInfo) {
        const { username, password } = userInfo;
        const usernameExit = await AdminModel.findOne({
            where: { username }
        })
        if (!usernameExit) {
            return 10003;
        }
        const dbPassword = usernameExit.get('password');
        if (password != dbPassword) {
            return 10004;
        }
        const uid = usernameExit.get('id');
        return {
            uid,
            username
        }
    }
}
module.exports = new AdminService();